<script setup lang="ts">
  import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import store from "./store";
  onLaunch(() => {
    console.log("App Launch");
  });
  onShow(() => {
    console.log("App Show");
  });
  onHide(() => {
    console.log("App Hide");
  });

  // 路由守护
  const authUrls=['/pages/pay','/pages/myorder']
  const routerInstance = (options): void => {
    const url: string | undefined = options.url
    if (authUrls.filter(authUrl => url?.startsWith(authUrl)).length > 0) {
      const token =store.getters.token
      if (token) {
        return
      }else{
        options.url = '/pages/login/index'
      }
    }
  }
  const routerFuncNameList = ["navigateTo", "redirectTo", "switchTab", "reLaunch"]
  routerFuncNameList.forEach(funcName => uni.addInterceptor(funcName, { invoke: (result) => routerInstance(result) }))


</script>
<style lang="less">

  .box {
    width: 300px;
    height: 300px;
    background-color: pink;
  }

  page {
    /* 如果支持安全区域 */
    padding-bottom: env(safe-area-inset-bottom);
    /* 顶部导航栏高度 */
    --status-bar-height: 44px;
  }

</style>
